home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- //////////////////////////////////////////////////////////////////////
- // Straight.c++ - definition of the straight class
- //
- // This class defines a straightaway stretch of road. It is
- // derived from the stretch abstract base class.
- //////////////////////////////////////////////////////////////////////
-
- #include <math.h>
- #include "Stretch.h"
- #include "Straight.h"
-
- Straight::Straight(
- Stretch *prev, Stretch *next,
- float length, float width, float hill_angle,
- float bank_angle, float loop_offset)
- : Stretch(prev, next)
- {
- _turn_angle = 0.0; // straights do not curve
-
- // specified in degrees, stored as radians
- _hill_angle = hill_angle*M_PI/180.0;
- _bank_angle = bank_angle*M_PI/180.0;
-
- _length = length;
- _width = width;
-
- if (loop_offset == 0.0)
- {
- _type = STRAIGHT;
- _step = 30.0;
- }
- else
- {
- _type = LOOP;
- _step = 15.0;
- }
-
- // compute radius of the hill, if it's not flat
- if (_hill_angle != 0.0)
- _hill_radius = _length/_hill_angle;
-
- Stretch::compute_step();
- Stretch::allocate_data();
-
- // find the accumulated offset and orientation
- SbVec3f prev_offset;
- SbRotation prev_orientation;
- Stretch::find_previous(prev_offset, prev_orientation);
-
- make_straight(prev_offset,prev_orientation, loop_offset);
-
- // match up ends
- Stretch::match_ends();
-
- Stretch::init_scenery();
- }
-
-
- Straight::~Straight()
- {
- }
-
-
- void Straight::make_straight(SbVec3f prev_offset,
- SbRotation prev_orientation, float loop_offset)
- {
- SbVec3f left, middle, right;
-
- // set initial values for x coordinates
- left.setValue(- _width/2.0,0.0,0.0);
- middle.setValue(0.0,0.0,0.0);
- right.setValue(_width/2.0,0.0,0.0);
-
- // compute the 'center' of the hill
- // use later to find the normals
- SbVec3f center(middle[0],_hill_radius,0.0);
-
- float bank_step = _bank_angle/(_length/_step);
- float bank = 0.0;
-
- float z = 0.0;
-
- for (int i = 0; i < _num_markers; i++)
- {
-
- if (_hill_angle == 0.0)
- {
- // straight is flat
- left[1] = middle[1] = right[1] = 0.0;
- left[2] = middle[2] = right[2] = -z;
-
- _data[i].normal.setValue(0.0,1.0,0.0);
-
- }
- else
- {
- // straight is a hill
- left[1] = middle[1] = right[1] =
- _hill_radius * (1.0 - fcos(_hill_angle * z/_length));
-
- left[2] = middle[2] = right[2] =
- - _hill_radius * fsin(_hill_angle * z/_length);
-
- // Compute the normal
- _data[i].normal = center - middle;
- _data[i].normal.normalize();
-
- if (_hill_radius < 0.0)
- {
- // XXX Do X as well ?
-
- _data[i].normal[1] *= -1.0;
- _data[i].normal[2] *= -1.0;
- }
- }
-
- _data[i].left = left;
- _data[i].middle = middle;
- _data[i].right = right;
-
- float partial_loop_offset =
- loop_offset*(float)i/(float)(_num_markers - 1);
-
- _data[i].left[0] += partial_loop_offset;
- _data[i].middle[0] += partial_loop_offset;
- _data[i].right[0] += partial_loop_offset;
-
- // rotate the data and the normals about the center
- // of the road by bank radians counter clockwise
- Stretch::rotate_bank(i,bank);
- bank += bank_step;
-
- z += _step;
- }
-
- SbRotation this_quat(_data[0].normal,_data[_num_markers - 1].normal);
- _orientation = this_quat * prev_orientation;
-
- Stretch::transform_data(prev_offset, prev_orientation);
- }
-
-